package com.app.micaihu.view.home.questions.adapter

import android.view.View
import android.widget.ImageView
import com.app.micaihu.R
import com.app.micaihu.configure.Config
import com.app.micaihu.configure.UmEventId
import com.app.micaihu.utils.MobclickAgentUtils
import com.app.micaihu.utils.StatServiceUtils
import com.app.micaihu.view.bean.QuestionList
import com.app.micaihu.view.utils.loadCircleImage
import com.app.micaihu.view.utils.loadImage
import com.app.utils.util.view.expression.view.BiaoQinTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 问答列表 适配器
 */
class QuestionsListAdapter : BaseQuickAdapter<QuestionList.Cmt, BaseViewHolder>(R.layout.question_list_item), LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: QuestionList.Cmt) {
        StatServiceUtils.event(Config.EventBauduId.answerlist_exposure, "问答列表曝光")
        MobclickAgentUtils.event(UmEventId.answer_exposed, "问答列表_曝光")
        holder.apply {
            setText(R.id.tvTitle, item.title)
            setText(R.id.tvAnswerNum, item.replyNum + "回答")

            val cmtList = item.cmtList
            if (cmtList.isNullOrEmpty()) {
                setGone(R.id.rlAnswer, true)
                setVisible(R.id.cardAnswerBtn, true)
            } else {
                setGone(R.id.cardAnswerBtn, true)
                setVisible(R.id.rlAnswer, true)
                cmtList[0].let {
                    getView<ImageView>(R.id.ivAuthorImage).loadCircleImage(it.headPic, R.drawable.user_head_def)
                    getView<ImageView>(R.id.ivRankIcon).loadImage(it.rankIcon)
                    if (com.blankj.utilcode.util.StringUtils.isEmpty(item.honourPic)) {
                        getView<ImageView>(R.id.ivHonourPic).visibility = View.GONE
                    } else {
                        getView<ImageView>(R.id.ivHonourPic).visibility = View.VISIBLE
                        getView<ImageView>(R.id.ivHonourPic).loadImage(item.honourPic)
                    }
                    setText(R.id.tvAuthorName, it.nickName)
                    setText(R.id.tvRankName, it.rankName)
                    setText(R.id.tvArmyGroupInfo, it.armyGroupInfo)
                    setText(R.id.tvPublishTime, it.publishTime)
                    getView<BiaoQinTextView>(R.id.tvFirstAnswer).setPicText(it.content)
                }
            }
        }

    }


}